<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>fielddescriptor_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_proto2_fielddescriptor_test.js.html">fielddescriptor_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.proto2.FieldDescriptorTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.proto2.FieldDescriptorTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.proto2.FieldDescriptor&#39;);
<a name="line19"></a>goog.require(&#39;goog.proto2.Message&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line21"></a>
<a name="line22"></a>function testFieldDescriptorConstruction() {
<a name="line23"></a>  var messageType = {};
<a name="line24"></a>  var fieldDescriptor = new goog.proto2.FieldDescriptor(messageType, 10, {
<a name="line25"></a>    name: &#39;test&#39;,
<a name="line26"></a>    repeated: true,
<a name="line27"></a>    fieldType: goog.proto2.FieldDescriptor.FieldType.INT32,
<a name="line28"></a>    type: Number
<a name="line29"></a>  });
<a name="line30"></a>
<a name="line31"></a>  assertEquals(10, fieldDescriptor.getTag());
<a name="line32"></a>  assertEquals(&#39;test&#39;, fieldDescriptor.getName());
<a name="line33"></a>
<a name="line34"></a>  assertEquals(true, fieldDescriptor.isRepeated());
<a name="line35"></a>
<a name="line36"></a>  assertEquals(goog.proto2.FieldDescriptor.FieldType.INT32,
<a name="line37"></a>      fieldDescriptor.getFieldType());
<a name="line38"></a>  assertEquals(Number, fieldDescriptor.getNativeType());
<a name="line39"></a>  assertEquals(0, fieldDescriptor.getDefaultValue());
<a name="line40"></a>}
<a name="line41"></a>
<a name="line42"></a>function testGetDefaultValueOfString() {
<a name="line43"></a>  var fieldDescriptor = new goog.proto2.FieldDescriptor({}, 10, {
<a name="line44"></a>    name: &#39;test&#39;,
<a name="line45"></a>    fieldType: goog.proto2.FieldDescriptor.FieldType.STRING,
<a name="line46"></a>    type: String
<a name="line47"></a>  });
<a name="line48"></a>
<a name="line49"></a>  assertEquals(&#39;&#39;, fieldDescriptor.getDefaultValue());
<a name="line50"></a>}
<a name="line51"></a>
<a name="line52"></a>function testGetDefaultValueOfBool() {
<a name="line53"></a>  var fieldDescriptor = new goog.proto2.FieldDescriptor({}, 10, {
<a name="line54"></a>    name: &#39;test&#39;,
<a name="line55"></a>    fieldType: goog.proto2.FieldDescriptor.FieldType.BOOL,
<a name="line56"></a>    type: Boolean
<a name="line57"></a>  });
<a name="line58"></a>
<a name="line59"></a>  assertEquals(false, fieldDescriptor.getDefaultValue());
<a name="line60"></a>}
<a name="line61"></a>
<a name="line62"></a>function testGetDefaultValueOfInt64() {
<a name="line63"></a>  var fieldDescriptor = new goog.proto2.FieldDescriptor({}, 10, {
<a name="line64"></a>    name: &#39;test&#39;,
<a name="line65"></a>    fieldType: goog.proto2.FieldDescriptor.FieldType.INT64,
<a name="line66"></a>    type: String
<a name="line67"></a>  });
<a name="line68"></a>
<a name="line69"></a>  assertEquals(&#39;0&#39;, fieldDescriptor.getDefaultValue());
<a name="line70"></a>}
<a name="line71"></a>
<a name="line72"></a>function testRepeatedField() {
<a name="line73"></a>  var messageType = {};
<a name="line74"></a>  var fieldDescriptor = new goog.proto2.FieldDescriptor(messageType, 10, {
<a name="line75"></a>    name: &#39;test&#39;,
<a name="line76"></a>    repeated: true,
<a name="line77"></a>    fieldType: 7,
<a name="line78"></a>    type: Number
<a name="line79"></a>  });
<a name="line80"></a>
<a name="line81"></a>  assertEquals(true, fieldDescriptor.isRepeated());
<a name="line82"></a>  assertEquals(false, fieldDescriptor.isRequired());
<a name="line83"></a>  assertEquals(false, fieldDescriptor.isOptional());
<a name="line84"></a>}
<a name="line85"></a>
<a name="line86"></a>function testRequiredField() {
<a name="line87"></a>  var messageType = {};
<a name="line88"></a>  var fieldDescriptor = new goog.proto2.FieldDescriptor(messageType, 10, {
<a name="line89"></a>    name: &#39;test&#39;,
<a name="line90"></a>    required: true,
<a name="line91"></a>    fieldType: 7,
<a name="line92"></a>    type: Number
<a name="line93"></a>  });
<a name="line94"></a>
<a name="line95"></a>  assertEquals(false, fieldDescriptor.isRepeated());
<a name="line96"></a>  assertEquals(true, fieldDescriptor.isRequired());
<a name="line97"></a>  assertEquals(false, fieldDescriptor.isOptional());
<a name="line98"></a>}
<a name="line99"></a>
<a name="line100"></a>function testOptionalField() {
<a name="line101"></a>  var messageType = {};
<a name="line102"></a>  var fieldDescriptor = new goog.proto2.FieldDescriptor(messageType, 10, {
<a name="line103"></a>    name: &#39;test&#39;,
<a name="line104"></a>    fieldType: 7,
<a name="line105"></a>    type: Number
<a name="line106"></a>  });
<a name="line107"></a>
<a name="line108"></a>  assertEquals(false, fieldDescriptor.isRepeated());
<a name="line109"></a>  assertEquals(false, fieldDescriptor.isRequired());
<a name="line110"></a>  assertEquals(true, fieldDescriptor.isOptional());
<a name="line111"></a>}
<a name="line112"></a>
<a name="line113"></a>function testContaingType() {
<a name="line114"></a>  var MessageType = function() {
<a name="line115"></a>    goog.base(this);
<a name="line116"></a>  };
<a name="line117"></a>  goog.inherits(MessageType, goog.proto2.Message);
<a name="line118"></a>
<a name="line119"></a>  var descriptorObj = {
<a name="line120"></a>    0: {
<a name="line121"></a>      name: &#39;test_message&#39;,
<a name="line122"></a>      fullName: &#39;this.is.a.test_message&#39;
<a name="line123"></a>    },
<a name="line124"></a>    10: {
<a name="line125"></a>      name: &#39;test&#39;,
<a name="line126"></a>      fieldType: 7,
<a name="line127"></a>      type: Number
<a name="line128"></a>    }
<a name="line129"></a>  };
<a name="line130"></a>  goog.proto2.Message.set$Metadata(MessageType, descriptorObj);
<a name="line131"></a>
<a name="line132"></a>  var descriptor = MessageType.getDescriptor();
<a name="line133"></a>  var fieldDescriptor = descriptor.getFields()[0];
<a name="line134"></a>  assertEquals(&#39;10&#39;, fieldDescriptor.getTag());
<a name="line135"></a>  assertEquals(descriptor, fieldDescriptor.getContainingType());
<a name="line136"></a>}
</pre>


</body>
</html>
